package chatGUI;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Window;

import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;

import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Color;
import javax.swing.JButton;

import chatControler.ChatControler;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Classe qui gère la fenêtre principale du chat
 * Elle contient le pannel de la zone de travail
 * @author vincent
 */
public class EcranduChat extends JFrame /*implements WindowListener*/ {

    protected String pseudo;
    private ChatControler chatControler;
    protected EcrandeTravail ecranDeTravail;

    /**
     * Constructeur
     * @param pseudo : Nom de l'utilisateur local
     * @param chatControler : ChatControler du ChatSystem
     */
    public EcranduChat(String pseudo, ChatControler chatControler) {;
        this.chatControler = chatControler;
        JFrame cadre = new javax.swing.JFrame(pseudo);
        cadre.setSize(720, 700);
        this.ecranDeTravail = new EcrandeTravail(pseudo, chatControler);
        cadre.setContentPane(this.ecranDeTravail);
        cadre.setLocation(30, 30);
        cadre.setVisible(true);
        cadre.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
        cadre.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent arg0) {
                System.out.println("je vais fermer");
                fermer();
                dispose();
                System.exit(0);

            }
        });

    }
    
    /**
     * Ferme l'écran du chat
     * @see chatControler.ChatControler#setConnected(boolean) setConnected
     */
    public void fermer() {
        this.chatControler.setConnected(false);
    }
    /*	@Override
    public void windowActivated(WindowEvent arg0) {
    // TODO Auto-generated method stub
    
    }
    @Override
    public void windowClosed(WindowEvent arg0) {
    
    }
    @Override
    public void windowClosing(WindowEvent arg0) {
    //quand on clique sur la croix, il faut fermer tout le monde qu'on arrete l'application
    this.chatControler.setConnected(false);
    try {
    Thread.sleep(10);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.exit(0);	
    }
    @Override
    public void windowDeactivated(WindowEvent arg0) {
    // TODO Auto-generated method stub
    
    }
    @Override
    public void windowDeiconified(WindowEvent arg0) {
    // TODO Auto-generated method stub
    
    }
    @Override
    public void windowIconified(WindowEvent arg0) {
    // TODO Auto-generated method stub
    
    }
    @Override
    public void windowOpened(WindowEvent arg0) {
    // TODO Auto-generated method stub
    
    }
     */
}
